/**
 * @Author：ming
 * @Date：2023/9/26 10:15 AM
 * @Filename：Lc209
 */

/**
 * @author ming
 */
public class Lc209 {
    public int minSubArrayLen(int target, int[] nums) {
        int len = nums.length;
        int p =-1;
        int q =0;
        int sum = 0;
        int min = len+1;
        int count  = 0;
        boolean flag = true;
        while (q<len){
            if(flag){
                sum += nums[q];
            }

            if(sum<target){
                q++;
                flag = true;
            }else{
                count = q-p;
                if(count<min){
                    min = count;

                }
                p++;
                sum -= nums[p];
                flag = false;
            }
        }

        if(min==len+1){
            return 0;
        }
        return min;
    }
}
